package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"log"
	"mygin_project/controller"
	"mygin_project/tool"
)

func main() {

	cfg, err := tool.ParseConfig("./config/app.json")
	if err != nil {
		panic(err)
	}

	//连接数据库
	_, err = tool.OrmEngine(cfg)
	if err != nil {
		//返回数据
		log.Printf("OrmEngine wrong %s", err.Error())
		return
	}

	//设置运行模式
	gin.SetMode(cfg.AppMode)
	engine := gin.Default()

	//路由设置
	registerRouter(engine)

	//启动
	addr := fmt.Sprintf("%s:%s", cfg.AppHost, cfg.AppPort)
	engine.Run(addr)

}

//路由设置
func registerRouter(engine *gin.Engine)  {
	new(controller.HelloController).Router(engine)
	new(controller.SmsController).Router(engine)
	new(controller.MemberController).Router(engine)
}
